//
//  HighqualitycomponentsNBViewController.m
//  Gxj
//
//  Created by 💋索少杰 on 2017/10/17.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "HighqualitycomponentsNBViewController.h"
#import "ThanTheStormFromTableViewCell.h"
#import "QualitycreationdetailsNBViewController.h"

//数据
#import "ThanTheStormFromModel.h"

@interface HighqualitycomponentsNBViewController ()<UITableViewDelegate,UITableViewDataSource>

{
    //解析数据接收
    NSMutableArray * _thantheStormModeArr;
}

@property (nonatomic, strong) UITableView * tableView;

@end

@implementation HighqualitycomponentsNBViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addSubview:self.tableView];
    
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;  // 侧滑返回
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;// 去掉所有cell的分割线
    
    //创想风暴
    [self setThanTheStormModelUp];
}

#pragma mark    -数据解析
- (void)setThanTheStormModelUp
{
    NSString *userid = [KQUserDefaults readUserDataWithKey:@"userid"];
    
    NSDictionary *dicc = @{@"userid":userid,
                           @"type":@"1",
                           @"page":@"1",
                           @"index":@"3",
                           @"quality":@"0"
                           };
    
    [KQNetWork postWithURLString:[NSString stringWithFormat:@"%@/api/think/index",MAIN_URL] parameters:dicc success:^(NSDictionary *dic) {
        
        _thantheStormModeArr = [NSMutableArray array];
        
        ThanTheStormFromModel * model = [[ThanTheStormFromModel alloc] init];
        
        [model setValuesForKeysWithDictionary:dic];
        
        for (NSDictionary * listDic in model.list)
        {
            ThanTheStormFromModel_list * model_list = [[ThanTheStormFromModel_list alloc] init];
            
            [model_list setValuesForKeysWithDictionary:listDic];
            
            [_thantheStormModeArr addObject:model_list];
            
            [self.tableView reloadData];
        }
    }
      failure:^(NSError *error)
     {
         NSLog(@"请求错误");
     }];
}



//返回每个分区下的单元格个数，必须实现
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _thantheStormModeArr.count;
    //return 3;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return kHeightScale(295);
}
///*设置标题尾的宽度*/
//-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
//{
//    return kHeightScale(50);
//}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * str= @"biao";
    ThanTheStormFromTableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:str];
    if (!cell) {
        
        cell=[[ThanTheStormFromTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }
    cell.model = _thantheStormModeArr[indexPath.row];
    cell.selectionStyle=UITableViewStylePlain;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.navigationController pushViewController:[QualitycreationdetailsNBViewController new] animated:YES
     ];
}


- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kHeightScale(44), UIScreenWidth, UIScreenHeight-95) style:UITableViewStylePlain];
        
        _tableView.delegate = self;
        
        _tableView.dataSource = self;
    }
    return _tableView;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
